package com.qzdsoft.erpcloud.service.com.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.qzdsoft.erpcloud.domain.com.CustomerSupplierContacts;
import com.qzdsoft.erpcloud.mapper.com.CustomerSupplierContactsMapper;
import com.qzdsoft.erpcloud.mapper.com.CustomerSupplierContactsQueryMapper;
import com.qzdsoft.erpcloud.service.com.CustomerSupplierContactService;
import com.qzdsoft.erpcloud.vo.com.CustomerSupplierContactsInfo;
import com.qzdsoft.erpcloud.vo.com.CustomerSupplierContactsQueryParam;
import com.qzdsoft.vo.LayTableResponse;
import com.qzdsoft.vo.Response;

/**
 * Created by yyb on 2017/7/2 0002.
 */
@Service
public class CustomerSupplierContactServiceImpl implements CustomerSupplierContactService {

    @Autowired
    private CustomerSupplierContactsMapper comContactsMapper;
    @Autowired
    private CustomerSupplierContactsQueryMapper comContactsQueryMapper;

    @Override
    public CustomerSupplierContacts selectById(Integer id) {
        return comContactsMapper.selectByPrimaryKey(id);
    }


    @Override
    public Response edit(CustomerSupplierContacts contacts) {
        if(null != contacts.getId()){        //  编辑
//            int ui = comContactsMapper.updateByPrimaryKey(contacts);
        	comContactsMapper.updateByPrimaryKeySelective(contacts);
            return Response.success("编辑成功");
        } else {
            contacts.setCtime(new Date());
            comContactsMapper.insert(contacts);
            return Response.success("新增成功");
        }
    }
    @Override
    public Response del(Integer id) {
        comContactsMapper.deleteByPrimaryKey(id);
        return Response.success(null);
    }

	@Override
	public LayTableResponse<CustomerSupplierContactsInfo> selectAll(CustomerSupplierContactsQueryParam info) {
		PageHelper.startPage(info.getPage(), info.getLimit());
		List<CustomerSupplierContactsInfo> lists = comContactsQueryMapper.selectAll(info);
		return new LayTableResponse<CustomerSupplierContactsInfo>(lists);
	}
    
    
}
